let selectedBeverageType; let selectedBottleSize; let selectedBottleSystem; let selectedNewBottleSystem; let selectedPET; let numberProducedBottles; let increaseUseRecycledPET; let calcResults; let calcResults2; // Calculation constants const _0005 = 0.0000005; const _00055 = 0.00000055; const _0138 = 0.00000138; const _0176 = 0.00000176; const _0188 = 0.00000188; const _0226 = 0.00000226; const _0467 = 0.0000004675; const _0945 = 0.000000945; const _10395 = 0.0000010395; const _0231 = 0.00000231; const _189 = 1.89; const _278 = 2.78; const _091 = 0.91; const _1100 = 1100; const _1400 = 1400; let _EUR = 0.8452; // get this from API let lookUp = {}; // Calc 3 constants const CostPerTonVirginResin_Preform = 1200; const CostPerTonPCR_Preform = 1400; const CostPerTonResin_Closure = 1500; const CO2SavedPerTonVirginResin_Preform = 2780; const CO2SavedPerTonPCR_Preform = 910; const CO2SavedPerTonResin_Closure =1890; // #region helper functions function setBeverageType(el) { const selectorClassName = "beverage-type"; const defaultCardClass = "uk-card-default"; const selectedCardClass = "uk-card-primary"; const validationClass = "validation-beverage-type"; const eloquaFieldName = "beverageType1"; clearSelections(selectorClassName, defaultCardClass, selectedCardClass); setSelection(el, defaultCardClass, selectedCardClass); selectedBeverageType = el.dataset.value; console.log('1- Selected Beverage Type: ' + selectedBeverageType); setEloquaFieldValue(eloquaFieldName, selectedBeverageType); clearValidationDanger(validationClass, validationClass + '-msg'); clearBottleSelections(); clearHideCurrentSystem(true); clearHideNewSystem(true); showBottleSize(lookUp.application[selectedBeverageType].bottleSize.options); } function clearBottleSelections() { const selectorClassName = "bottle-size"; const defaultTileClass = "uk-tile-muted"; const selectedTitleClass = "uk-tile-primary"; const eloquaFieldName = "bottleSize1"; selectedBottleSize = ""; clearSelections(selectorClassName, defaultTileClass, selectedTitleClass); setEloquaFieldValue(eloquaFieldName, selectedBottleSize); } function clearHideCurrentSystem(hide) { const selectorClassName = "bottle-system"; const defaultTileClass = "default-bottle-system"; const selectedTitleClass = "selected-bottle-system"; const validationClass = "validation-bottle-system"; const eloquaFieldName = "lightweightDispensingSystem1"; selectedBottleSystem = ""; if (hide) { hideCurrentSystem(); } clearSelections(selectorClassName, defaultTileClass, selectedTitleClass); setEloquaFieldValue(eloquaFieldName, selectedBottleSystem) } function clearHideNewSystem(hide) { const selectorClassName = "new-bottle-system"; const defaultTileClass = "default-bottle-system"; const selectedTitleClass = "selected-bottle-system"; const validationClass = "validation-bottle-system"; const eloquaFieldName = "lightweightDispensingSystem1"; selectedNewBottleSystem = ""; clearSelections(selectorClassName, defaultTileClass, selectedTitleClass); if (hide) { hideNewSystem(); } setEloquaFieldValue(eloquaFieldName, selectedNewBottleSystem) } function setBottleSize(el) { const selectorClassName = "bottle-size"; const defaultTileClass = "uk-tile-muted"; const selectedTitleClass = "uk-tile-primary"; const validationClass = "validation-bottle-size"; const eloquaFieldName = "bottleSize1"; clearSelections(selectorClassName, defaultTileClass, selectedTitleClass); setSelection(el, defaultTileClass, selectedTitleClass); selectedBottleSize = el.dataset.value; console.log('2- Selected Bottle Size: ' + selectedBottleSize); setEloquaFieldValue(eloquaFieldName, selectedBottleSize) clearHideCurrentSystem(false); clearHideNewSystem(true); clearValidationDanger(validationClass, validationClass + '-msg'); showCurrentSystem(lookUp.application[selectedBeverageType].bottleSize[mapBottleSize(selectedBottleSize)].currentDisplay.options) } function setBottleSystem(el) { const selectorClassName = "bottle-system"; const defaultTileClass = "default-bottle-system"; const selectedTitleClass = "selected-bottle-system"; const validationClass = "validation-bottle-system"; const eloquaFieldName = "cALC2622INCurrentDispensingSystem1"; clearSelections(selectorClassName, defaultTileClass, selectedTitleClass); setSelection(el, defaultTileClass, selectedTitleClass); selectedBottleSystem = el.dataset.value; console.log('3- Selected Bottle System: ' + selectedBottleSystem); setEloquaFieldValue(eloquaFieldName, selectedBottleSystem) clearHideNewSystem(false); clearValidationDanger(validationClass, validationClass + '-msg'); showNewSystem(lookUp.application[selectedBeverageType].bottleSize[mapBottleSize(selectedBottleSize)].currentDisplay[selectedBottleSystem].futureDisplay.options) } function setNewBottleSystem(el) { const selectorClassName = "new-bottle-system"; const defaultTileClass = "default-bottle-system"; const selectedTitleClass = "selected-bottle-system"; const validationClass = "validation-new-system"; const eloquaFieldName = "lightweightDispensingSystem1"; clearSelections(selectorClassName, defaultTileClass, selectedTitleClass); setSelection(el, defaultTileClass, selectedTitleClass); selectedNewBottleSystem = el.dataset.value; console.log('4- Selected New Bottle System: ' + selectedNewBottleSystem); setEloquaFieldValue(eloquaFieldName, selectedNewBottleSystem) clearValidationDanger(validationClass, validationClass + '-msg'); } function setNumberProducedBottle(el) { const validationClass = "validation-number-bottle"; const eloquaFieldName = "bottlesProducedYearly1"; numberProducedBottles = el.value; numberProducedBottles = numberProducedBottles.replace(/,/g,""); console.log('4- Number Produced Bottles: ' + numberProducedBottles); setEloquaFieldValue(eloquaFieldName, numberProducedBottles) clearValidationDanger(validationClass, validationClass + '-msg'); el.value = formatNumber().format(numberProducedBottles); } function setSelectedPET(el) { const validationClass = "validation-recycled-pet"; const eloquaFieldName = "percentageRecycledPET1"; selectedPET = el.value; if (selectedPET === -1) { setEloquaFieldValue(eloquaFieldName, ""); return; } console.log('5- Selected PET: ' + selectedPET); setEloquaFieldValue(eloquaFieldName, selectedPET) clearValidationDanger(validationClass, validationClass + '-msg'); } function setIncreaseUseRecycledPET(el) { const validationClass = "validation-increase-pet"; const eloquaFieldName = "increaseRecycledPET1"; increaseUseRecycledPET = el.value; if (increaseUseRecycledPET === -1) { setEloquaFieldValue(eloquaFieldName, ""); return; } console.log('6- Increase use of recycled PET: ' + increaseUseRecycledPET); setEloquaFieldValue(eloquaFieldName, increaseUseRecycledPET) clearValidationDanger(validationClass, validationClass + '-msg'); } function doCalculations() { if (!isFormValid()) { UIkit.modal("#validation-modal").show() return false; } /*doCo2SavingsCalculation(); doResinSavingsCalculation(); doCostSavingsCalculation();*/ // setSelectedSystem(); calculateResinSavings(); calculateCO2Savings(); calculateResinCost(); setLocalStorage(); // setCookie(); setSubmitTrue(); } function clearSelections(selectorClassName, defaultClass, selectedClass) { const allElements = document.getElementsByClassName(selectorClassName); for(var i=0; i < allElements.length; i++) { if (allElements[i].classList.contains(selectedClass)) { allElements[i].classList.remove(selectedClass); allElements[i].classList.add(defaultClass); } } } function setSelection(el, defaultClass, selectedClass) { el.classList.remove(defaultClass); el.classList.add(selectedClass); } function clearValidationDanger(className, msgClass) { const elements = document.getElementsByClassName(className); const message = document.getElementsByClassName(msgClass); for(var i=0; i < elements.length; i++) { elements[i].classList.remove('uk-form-danger'); } message[0].style.display = 'none'; } function setEloquaFieldValue(eloquaFieldName, fieldValue) { const eloquaField = document.getElementsByName(eloquaFieldName); if(eloquaField && eloquaField.length > 0 ) { eloquaField[0].value = fieldValue; return; } console.log('############----Oops something went wrong! No Eloqua Field mapped------#########'); } function doCo2SavingsCalculation(type) { // CO2 PET Savings const RESULT_CO2_PET_SAVINGS = calculateCO2PETSavings(); calcResults[1881].calculations.co2PET = RESULT_CO2_PET_SAVINGS; calcResults[3037].calculations.co2PET = RESULT_CO2_PET_SAVINGS; calcResults[3038].calculations.co2PET = RESULT_CO2_PET_SAVINGS; console.log('CO2 PET Savings (tons): ' + RESULT_CO2_PET_SAVINGS); // setEloquaFieldValue("", RESULT_CO2_PET_SAVINGS.toFixed(1)); // 1881 const RESULT_CO2_1881LW = calculate1881CO2Savings(); calcResults[1881].calculations.co2 = RESULT_CO2_1881LW; console.log('1818LW - CO2 Savings (tons): ' + calcResults[1881].calculations.co2.toFixed(1)); setEloquaFieldValue("cALC2622OUT1881LWCO21", calcResults[1881].calculations.co2.toFixed(1)); // 3037 const RESULT_CO2_3037 = calculate3037CO2Savings(); calcResults[3037].calculations.co2 = RESULT_CO2_3037; console.log('3037 - CO2 Savings (tons): ' + calcResults[3037].calculations.co2.toFixed(1)); setEloquaFieldValue("cALC2622OUT3037CO21", calcResults[3037].calculations.co2.toFixed(1)); // 3038 const RESULT_CO2_3038 = calculate3038CO2Savings(); calcResults[3038].calculations.co2 = RESULT_CO2_3038; console.log('3038 - CO2 Savings (tons): ' + calcResults[3038].calculations.co2.toFixed(1)); setEloquaFieldValue("cALC2622OUT3038CO21", calcResults[3038].calculations.co2.toFixed(1)); } function doResinSavingsCalculation() { // 1881 const RESULT_RESIN_1881LW = calculate1881ResinSavings(); calcResults[1881].calculations.resin = RESULT_RESIN_1881LW; console.log('1818LW - Resin Savings (tons): ' + calcResults[1881].calculations.resin.toFixed(1)); setEloquaFieldValue("cALC2622OUT1881LWResin1", calcResults[1881].calculations.resin.toFixed(1)); //3037 const RESULT_RESIN_3037 = calculate3037ResinSavings(); calcResults[3037].calculations.resin = RESULT_RESIN_3037; console.log('3037 - Resin Savings (tons): ' + RESULT_RESIN_3037.toFixed(1)); setEloquaFieldValue("cALC2622OUT3037Resin1", calcResults[3037].calculations.resin.toFixed(1)); //3038 const RESULT_RESIN_3038 = calculate3038ResinSavings(); calcResults[3038].calculations.resin = RESULT_RESIN_3038; console.log('3038 - Resin Savings (tons): ' + calcResults[3038].calculations.resin.toFixed(1)); setEloquaFieldValue("cALC2622OUT3038Resin1", calcResults[3038].calculations.resin.toFixed(1)); } function doCostSavingsCalculation() { // 1881 const RESULT_USD_SAV_1881LW = calculate1881CostUsdSavings(); const RESULT_EUR_SAV_1881LW = calculateCostEURSavings(RESULT_USD_SAV_1881LW); calcResults[1881].calculations.costSavingUSD = RESULT_USD_SAV_1881LW; calcResults[1881].calculations.costSavingEUR = RESULT_EUR_SAV_1881LW; console.log('1818LW - Cost Savings (USD): ' + calcResults[1881].calculations.costSavingUSD.toFixed(2)); console.log('1818LW - Cost Savings (EUR): ' + calcResults[1881].calculations.costSavingEUR.toFixed(2)); setEloquaFieldValue("cALC2622OUT1881LWUSD1", formatter().format(RESULT_USD_SAV_1881LW)); setEloquaFieldValue("cALC2622OUT1881LWEURO1", formatterEUR().format(RESULT_EUR_SAV_1881LW)); //3037 const RESULT_USD_SAV_3037 = calculate3037CostUsdSavings(); const RESULT_EUR_SAV_3037 = calculateCostEURSavings(RESULT_USD_SAV_3037); calcResults[3037].calculations.costSavingUSD = RESULT_USD_SAV_3037; calcResults[3037].calculations.costSavingEUR = RESULT_EUR_SAV_3037; console.log('3037 - Cost Savings (USD): ' + calcResults[3037].calculations.costSavingUSD.toFixed(2)); console.log('3037 - Cost Savings (EUR): ' + calcResults[3037].calculations.costSavingEUR.toFixed(2)); setEloquaFieldValue("cALC2622OUT3037USD1", formatter().format(RESULT_USD_SAV_3037)); setEloquaFieldValue("cALC2622OUT3037EURO1", formatterEUR().format(RESULT_EUR_SAV_3037)); //3038 const RESULT_USD_SAV_3038 = calculate3038CostUsdSavings(); const RESULT_EUR_SAV_3038 = calculateCostEURSavings(RESULT_USD_SAV_3038); calcResults[3038].calculations.costSavingUSD = RESULT_USD_SAV_3038; calcResults[3038].calculations.costSavingEUR = RESULT_EUR_SAV_3038; console.log('3038 - Cost Savings (USD): ${calcResults[3038].calculations.costSavingUSD.toFixed(2)}'); console.log('3038 - Cost Savings (EUR): ${calcResults[3038].calculations.costSavingEUR.toFixed(2)}'); setEloquaFieldValue("cALC2622OUT3038USD1", formatter().format(RESULT_USD_SAV_3038)); setEloquaFieldValue("cALC2622OUT3038EURO1", formatterEUR().format(RESULT_EUR_SAV_3038)); } function calculateCO2PETSavings() { return (_0467 * selectedPET/100 * numberProducedBottles); } /** * 1881LW Specific Calculations */ // CO2 Savings function calculate1881CO2Savings() { return ((1 - (selectedPET/100)) * numberProducedBottles * _0005 * _278) + ((selectedPET/100) * numberProducedBottles * _0005 * _091); } // Resin Savings function calculate1881ResinSavings() { return (numberProducedBottles * _0005); } // Calculate USD cost savings function calculate1881CostUsdSavings() { return ((1 - (selectedPET/100)) * numberProducedBottles * _0005 * _1100) + ((selectedPET/100) * numberProducedBottles * _0005 *_1400); } /** * 3037 Specific Calculations * */ function calculate3037CO2Savings() { const calc1 = ((1 - (selectedPET/100)) * numberProducedBottles * _0138 * _278) + ((selectedPET/100) * numberProducedBottles * _0138 * _091); // const calc2 = ((1 - (selectedPET/100)) * numberProducedBottles * _0005 * _189) + ((selectedPET/100) * numberProducedBottles * _0005 * _091); const calc2 = (_0945 * numberProducedBottles); return calc1 + calc2; } // Resin Savings function calculate3037ResinSavings() { return (numberProducedBottles * _0188); } // Calculate USD cost savings function calculate3037CostUsdSavings() { return ((1 - (selectedPET/100)) * numberProducedBottles * _0138 * _1100) + ((selectedPET/100) * numberProducedBottles * _0138 *_1400) + (numberProducedBottles * _0005 * _1400); } /** * 3038 Specific Calculations * */ function calculate3038CO2Savings() { const calc1 = ((1 - (selectedPET/100)) * numberProducedBottles * _0176 * _278) + ((selectedPET/100) * numberProducedBottles * _0176 * _091); // const calc2 = ((1 - (selectedPET/100)) * numberProducedBottles * _0005 * _189) + ((selectedPET/100) * numberProducedBottles * _0005 * _091); const calc2 = (_10395 * numberProducedBottles); return calc1 + calc2; } // Resin Savings function calculate3038ResinSavings() { // return (numberProducedBottles * _0226); return (_0231 * numberProducedBottles); } // Calculate USD cost savings function calculate3038CostUsdSavings() { return ((1 - (selectedPET/100)) * numberProducedBottles * _0176 * _1100) + ((selectedPET/100) * numberProducedBottles * _0176 *_1400) + (numberProducedBottles * _00055 * _1400); } function calculateCostEURSavings(USD) { return USD * _EUR; } function initResultSet() { calcResults = { 3037 : { img: 'http://img.en25.com/Web/HuskyInjectionMoldingSystemsLtd/{68535e3d-24a7-4bed-ba30-1c7354f5ff29}_bottle_3037.jpg', productTitle: '26/22 GME 30.37', selected : false, resin: "1.88", preform: "1.38", closure: "0.50", calculations : { co2PET: 0, co2: 0, resin: 0, costSavingUSD: 0, costSavingEUR: 0 } }, 3038 : { img: 'http://img.en25.com/Web/HuskyInjectionMoldingSystemsLtd/{6710892c-b96a-490e-aa3d-70285641ce92}_bottle_3038.jpg', productTitle: '26/22 GME 30.38', selected : false, resin: "2.31", preform: "1.76", closure: "0.55", calculations : { co2PET: 0, co2: 0, resin: 0, costSavingUSD: 0, costSavingEUR: 0 } }, 1881 : { img: 'http://img.en25.com/Web/HuskyInjectionMoldingSystemsLtd/{d87d4728-2500-448c-bcf0-cd2ab240c6e0}_bottle_1881.jpg', productTitle: 'PCO 1881 LIGHTWEIGHT', selected : false, resin: "0.50", preform: "0.50", closure: "0.00", calculations : { co2PET: 0, co2: 0, resin: 0, costSavingUSD: 0, costSavingEUR: 0 } } } } function initResultSet2() { calcResults2 = { img: '', imgBanner : "", showTetheredBlock : false, productTitle: '', selected : false, preform : 0, closure: 0, calculations : { co2Savings: 0, resinSavingsTons: 0, resinCostSavings: 0, resinCostSavingUSD: 0, resinCostSavingEUR: 0 } } } function clearLocalStorage() { const localStorage = window.localStorage; localStorage.removeItem('calcResults2'); localStorage.removeItem('selectedBeverageType'); localStorage.removeItem('selectedPET'); localStorage.removeItem('selectedNewBottleSystem'); console.log("Local Storage is clear"); } function setLocalStorage() { calcResults2.preform = getPerPreformWeightSavings("grams"); calcResults2.closure = getPerClosureWeightSavings("grams"); const localStorage = window.localStorage; localStorage.setItem('calcResults2', JSON.stringify(calcResults2)); localStorage.setItem('selectedPET', selectedPET); localStorage.setItem('numberProducedBottles', numberProducedBottles); localStorage.setItem('selectedNewBottleSystem', selectedNewBottleSystem); console.log("*****Local Storage is SET*****"); console.log(JSON.parse(localStorage.getItem('calcResults2'))); console.log("******************************"); localStorage.setItem('selectedBeverageType',selectedBeverageType); setEloquaFieldValue("cALC2622OUTSummary1", JSON.stringify(calcResults2)); } function setSelectedSystem() { calcResults[selectedBottleSystem].selected = true; } function calculator() { // init lookup table initLookUpTable(); clearLocalStorage(); // init base result set initResultSet2(); // setCookie(); const elSubmit = document.getElementById("fe5097"); elSubmit.addEventListener('click', function() { doCalculations(); }); // http://campaign.husky.ca/CALC-INPUTS-Working loadEUREx(); } function isFormValid() { let valid = true; if (!selectedBeverageType) { const elements = document.getElementsByClassName("validation-beverage-type"); const message = document.getElementsByClassName("validation-beverage-type-msg"); for (i=0; i < elements.length; i++) { elements[i].classList.add('uk-form-danger') } message[0].style.display = 'block'; valid = false; } if (!selectedBottleSize) { const elements = document.getElementsByClassName("validation-bottle-size"); const message = document.getElementsByClassName("validation-bottle-size-msg"); for (i=0; i < elements.length; i++) { elements[i].classList.add('uk-form-danger') } message[0].style.display = 'block'; valid = false; } if (!selectedBottleSystem) { const elements = document.getElementsByClassName("validation-bottle-system"); const message = document.getElementsByClassName("validation-bottle-system-msg"); for (i=0; i < elements.length; i++) { elements[i].classList.add('uk-form-danger') } message[0].style.display = 'block'; valid = false; } if (!selectedNewBottleSystem) { const elements = document.getElementsByClassName("validation-new-system"); const message = document.getElementsByClassName("validation-new-system-msg"); for (i=0; i < elements.length; i++) { elements[i].classList.add('uk-form-danger') } message[0].style.display = 'block'; valid = false; } if (!selectedPET) { const elements = document.getElementsByClassName("validation-recycled-pet"); const message = document.getElementsByClassName("validation-recycled-pet-msg"); for (i=0; i < elements.length; i++) { elements[i].classList.add('uk-form-danger') } message[0].style.display = 'block'; valid = false; } if (!numberProducedBottles || numberProducedBottles === 0 ) { const elements = document.getElementsByClassName("validation-number-bottle"); const message = document.getElementsByClassName("validation-number-bottle-msg"); for (i=0; i < elements.length; i++) { elements[i].classList.add('uk-form-danger') } message[0].style.display = 'block'; valid = false; } if (!increaseUseRecycledPET) { const elements = document.getElementsByClassName("validation-increase-pet"); const message = document.getElementsByClassName("validation-increase-pet-msg"); for (i=0; i < elements.length; i++) { elements[i].classList.add('uk-form-danger') } message[0].style.display = 'block'; valid = false; } return valid; } function setSubmitTrue() { console.log("CAN SUBMIT: " + true); setEloquaFieldValue("cALC2622CanSubmit1", true); } function formatter() { return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'USD', minimumFractionDigits: 2 }); } function formatterEUR() { return new Intl.NumberFormat('en-US', { style: 'currency', currency: 'EUR', minimumFractionDigits: 2 }); } function formatNumber() { return new Intl.NumberFormat('en-US', { maximumSignificantDigits: 20 }); } function loadEUREx() { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { const rates = JSON.parse(this.responseText); _EUR = rates.USD_EUR; console.log("***** EUR Xchnage*******: " + _EUR); } }; xhttp.open("GET", "https://free.currconv.com/api/v7/convert?q=USD_EUR&compact=ultra&apiKey=9cf55870bc994ec087a7", true); xhttp.send(); } function initCalcFields() { document.getElementById("numberProducedBottles").value = ""; document.getElementById("recyclePET").value = -1; document.getElementById("planPET").value = -1; setEloquaFieldValue("cALC2622CanSubmit1", ""); } function callback() { calculator(); UIkit.modal("#validation-modal", {}); initCalcFields(); }; if ( document.readyState === "complete" || (document.readyState !== "loading" && !document.documentElement.doScroll) ) { callback(); } else { document.addEventListener("DOMContentLoaded", callback); } // New calc // Show Bottle Sizes function showBottleSize(options) { let placeHolder = document.getElementById("bottlePlaceholder"); placeHolder.classList.add("uk-hidden"); let bottleGrid = document.getElementById("bottleGrid"); bottleGrid.classList.remove("uk-hidden"); var allElements = document.getElementsByClassName("bottle-size-div"); for (var i=0; i <= allElements.length; i++) { if (allElements[i] && allElements[i].id) { var size = options.find( e => e === allElements[i].id) if (size) { allElements[i].classList.remove("uk-hidden"); } else { allElements[i].classList.add("uk-hidden"); } } } } function hideBottleSizes() { let placeHolder = document.getElementById("bottlePlaceholder"); placeHolder.classList.remove("uk-hidden"); let bottleGrid = document.getElementById("bottleGrid"); bottleGrid.classList.add("uk-hidden"); var allElements = document.getElementsByClassName("bottle-size-div"); for (var i=0; i <= allElements.length; i++) { if (allElements[i] && allElements[i].id) { allElements[i].classList.add("uk-hidden"); } } } // Show dispencing System function showCurrentSystem(options) { let placeHolder = document.getElementById("currentSystem"); placeHolder.classList.add("uk-hidden"); let grid = document.getElementById("currentGrid"); grid.classList.remove("uk-hidden"); var allElements = document.getElementsByClassName("current-div"); for (var i=0; i <= allElements.length; i++) { if (allElements[i] && allElements[i].id) { var size = options.find( e => e === allElements[i].id) if (size) { allElements[i].classList.remove("uk-hidden"); } else { allElements[i].classList.add("uk-hidden"); } } } } function hideCurrentSystem(options) { let placeHolder = document.getElementById("currentSystem"); placeHolder.classList.remove("uk-hidden"); let grid = document.getElementById("currentGrid"); grid.classList.add("uk-hidden"); var allElements = document.getElementsByClassName("current-div"); for (var i=0; i <= allElements.length; i++) { if (allElements[i] && allElements[i].id) { allElements[i].classList.add("uk-hidden"); } } } // Show new system function showNewSystem(options) { let placeHolder = document.getElementById("newSystem"); placeHolder.classList.add("uk-hidden"); let grid = document.getElementById("newGrid"); grid.classList.remove("uk-hidden"); var allElements = document.getElementsByClassName("new-div"); for (var i=0; i <= allElements.length; i++) { if (allElements[i] && allElements[i].id) { let id = allElements[i].id.replace("new-",""); var size = options.find( e => e === id) if (size) { allElements[i].classList.remove("uk-hidden"); } else { allElements[i].classList.add("uk-hidden"); } } } } function hideNewSystem(options) { let placeHolder = document.getElementById("newSystem"); placeHolder.classList.remove("uk-hidden"); let grid = document.getElementById("newGrid"); grid.classList.add("uk-hidden"); var allElements = document.getElementsByClassName("new-div"); for (var i=0; i <= allElements.length; i++) { if (allElements[i] && allElements[i].id) { allElements[i].classList.add("uk-hidden"); } } } function mapBottleSize(value) { let lookUpBottleSize = "ANY"; switch (value) { case "0-600": if (selectedBeverageType === "HOT_FILL") { lookUpBottleSize = 600; } break; case "601-1000": if (selectedBeverageType === "HOT_FILL") { lookUpBottleSize = 601_1; } break; case "1001-1500": if (selectedBeverageType === "HOT_FILL") { lookUpBottleSize = 11_15; } break; case "1501-3000": if (selectedBeverageType === "NOT_HOT_FILL") { lookUpBottleSize = 16_3; } break; case "3000+": if (selectedBeverageType === "STILL") { lookUpBottleSize = 31_8; } break; default: lookUpBottleSize = "ANY" } return lookUpBottleSize; } function initLookUpTable() { lookUp = { application : { options: ["CARB", "STILL", "HOT_FILL", "NOT_HOT_FILL"], CARB : { bottleSize : { options : ["600", "601_1", "11_15", "16_3"], ANY : { currentDisplay :{ options : ["NF10", "NF12"], NF10 :{ futureDisplay : { options : ["NF12" , "NF21", "NF15", "NF16", "NF17"], NF12 : { neckSavings : 1.25, closuresavings : 0.5, displaySystemSavings : 1.75 }, NF21 : { neckSavings : 1.65, closuresavings : 0.6, displaySystemSavings : 2.25 }, NF15 : { neckSavings : 2.63, closuresavings : 1.05, displaySystemSavings : 3.68 }, NF16 : { neckSavings : 2.36, closuresavings : 1, displaySystemSavings : 3.36 }, NF17 : { neckSavings : 2.56, closuresavings : 1, displaySystemSavings : 3.56 }, } }, NF12 :{ futureDisplay : { options : ["NF21", "NF15", "NF16", "NF17"], NF21 : { neckSavings : 0.4, closuresavings : 0.1, displaySystemSavings : 0.5 }, NF15 : { neckSavings : 1.38, closuresavings : 0.55, displaySystemSavings : 1.93 }, NF16 : { neckSavings : 1.11, closuresavings : 0.5, displaySystemSavings : 1.61 }, NF17 : { neckSavings : 1.31, closuresavings : 0.5, displaySystemSavings : 1.81 } } }, } } } }, STILL : { bottleSize : { options : ["600", "601_1", "11_15", "16_3", "31_8"], ANY : { currentDisplay : { options: ["NF10", "NF12", "NF03", "NF07", "NF02", "NF01"], NF10: { futureDisplay: { options: ["NF12", "NF21", "NF15", "NF16", "NF17", "NF01", "NF23"], NF12 : { neckSavings : 1.25, closuresavings : 0.5, displaySystemSavings : 1.75 }, NF21 : { neckSavings : 1.65, closuresavings : 0.6, displaySystemSavings : 2.25 }, NF15 : { neckSavings : 2.63, closuresavings : 1.05, displaySystemSavings : 3.68 }, NF16 : { neckSavings : 2.36, closuresavings : 1, displaySystemSavings : 3.36 }, NF17 : { neckSavings : 2.56, closuresavings : 1, displaySystemSavings : 3.56 }, NF01 : { neckSavings : 3.11, closuresavings : 1.6, displaySystemSavings : 4.71 }, NF23 : { neckSavings : 3.78, closuresavings : 1.5, displaySystemSavings : 5.28 }, } }, NF12 : { futureDisplay : { options: ["NF21", "NF15", "NF16", "NF17", "NF01", "NF23"], NF21 : { neckSavings : 0.4, closuresavings : 0.1, displaySystemSavings : 0.5 }, NF15 : { neckSavings : 1.38, closuresavings : 0.55, displaySystemSavings : 1.93 }, NF16 : { neckSavings : 1.11, closuresavings : 0.5, displaySystemSavings : 1.61 }, NF17 : { neckSavings : 1.31, closuresavings : 0.5, displaySystemSavings : 1.81 }, NF01 : { neckSavings : 1.86, closuresavings : 1.1, displaySystemSavings : 2.96 }, NF23 : { neckSavings : 2.53, closuresavings : 1, displaySystemSavings : 3.53 } } }, NF03 : { futureDisplay: { options : ["NF15", "NF16", "NF17", "NF02", "NF18", "NF01", "NF14", "NF23"], NF15: { neckSavings : 1.49, closuresavings : 0.1, displaySystemSavings : 1.59 }, NF16: { neckSavings : 1.22, closuresavings : 0.05, displaySystemSavings : 1.27 }, NF17: { neckSavings : 1.42, closuresavings : 0.05, displaySystemSavings : 1.47 }, NF02: { neckSavings : 1.51, closuresavings : 0.4, displaySystemSavings : 1.91 }, NF18: { neckSavings : 1.82, closuresavings : 0.6, displaySystemSavings : 2.42 }, NF01: { neckSavings : 1.97, closuresavings : 0.65, displaySystemSavings : 2.62 }, NF14: { neckSavings : 2.96, closuresavings : 1.05, displaySystemSavings : 4.01 }, NF23: { neckSavings : 2.64, closuresavings : 0.55, displaySystemSavings : 3.19 }, } }, NF07: { futureDisplay: { options: ["NF15", "NF16", "NF17", "NF01", "NF14", "NF23"], NF15 : { neckSavings : 1.22, closuresavings : -0.15, displaySystemSavings : 1.07 }, NF16 : { neckSavings : 0.95, closuresavings : -0.2, displaySystemSavings : 0.75 }, NF17 : { neckSavings : 1.15, closuresavings : -0.2, displaySystemSavings : 0.95 }, NF01 : { neckSavings : 1.7, closuresavings : 0.4, displaySystemSavings : 2.1 }, NF14 : { neckSavings : 2.69, closuresavings : 0.8, displaySystemSavings : 3.49 }, NF23 : { neckSavings : 2.37, closuresavings : 0.3, displaySystemSavings : 2.67 } } }, NF02 : { futureDisplay: { options: ["NF18", "NF01", "NF14", "NF23"], NF18 : { neckSavings : 0.31, closuresavings : 0.2, displaySystemSavings : 0.51 }, NF01 : { neckSavings : 0.46, closuresavings : 0.25, displaySystemSavings : 0.71 }, NF14 : { neckSavings : 1.45, closuresavings : 0.65, displaySystemSavings : 2.1 }, NF23 : { neckSavings : 1.13, closuresavings : 0.15, displaySystemSavings : 1.28 } } }, NF01: { futureDisplay: { options : ["NF14", "NF23"], NF14 : { neckSavings : 0.99, closuresavings : 0.4, displaySystemSavings : 1.39 }, NF23 : { neckSavings : 0.67, closuresavings : -0.1, displaySystemSavings : 0.57 } } } } }, 31_8 : { currentDisplay : { options: ["NF04", "NF06"], NF04 : { futureDisplay : { options: ["NF19"], NF19 : { neckSavings : 1.19, closuresavings : 0.9, displaySystemSavings : 2.09 } } }, NF06 : { futureDisplay : { options: ["NF04", "NF19"], NF04 : { neckSavings : 4.76, closuresavings : 1.6, displaySystemSavings : 6.36 }, NF19 : { neckSavings : 5.95, closuresavings : 2.5, displaySystemSavings : 8.45 } } } } } } }, HOT_FILL : { bottleSize : { options : ["600", "601_1", "11_15"], 600 : { currentDisplay : { options : ["NF11", "NF13", "NF08"], NF11: { futureDisplay : { options : ["NF13", "NF22"], NF13 : { neckSavings : 1.65, closuresavings : 1.3, displaySystemSavings : 2.95 }, NF22 : { neckSavings : 2.44, closuresavings : 1.9, displaySystemSavings : 4.34 } } }, NF13 : { futureDisplay : { options : ["NF22"], NF22: { neckSavings : 0.79, closuresavings : 0.6, displaySystemSavings : 1.39 } } }, NF08 : { futureDisplay : { options : ["NF20"], NF20 : { neckSavings : 3.87, closuresavings : 1, displaySystemSavings : 4.87 } } } } }, 601_1 : { currentDisplay : { options : ["NF11", "NF13", "NF08", "NF09"], NF11: { futureDisplay : { options : ["NF13", "NF22"], NF13 : { neckSavings : 1.65, closuresavings : 1.3, displaySystemSavings : 2.95 }, NF22 : { neckSavings : 2.44, closuresavings : 1.9, displaySystemSavings : 4.34 } } }, NF13 : { futureDisplay : { options : ["NF22"], NF22: { neckSavings : 0.79, closuresavings : 0.6, displaySystemSavings : 1.39 } } }, NF08 : { futureDisplay : { options : ["NF20"], NF20 : { neckSavings : 3.87, closuresavings : 1, displaySystemSavings : 4.87 } } }, NF09 : { futureDisplay : { options : ["NF20"], NF20 : { neckSavings : 6.42, closuresavings : 2, displaySystemSavings : 8.42 } } } } }, 11_15 : { currentDisplay : { options : ["NF11", "NF13", "NF08", "NF09"], NF11: { futureDisplay : { options : ["NF13", "NF22"], NF13 : { neckSavings : 1.65, closuresavings : 1.3, displaySystemSavings : 2.95 }, NF22 : { neckSavings : 2.44, closuresavings : 1.9, displaySystemSavings : 4.34 } } }, NF13 : { futureDisplay : { options : ["NF22"], NF22: { neckSavings : 0.79, closuresavings : 0.6, displaySystemSavings : 1.39 } } }, NF08 : { futureDisplay : { options : ["NF20"], NF20 : { neckSavings : 3.87, closuresavings : 1, displaySystemSavings : 4.87 } } }, NF09 : { futureDisplay : { options : ["NF20"], NF20 : { neckSavings : 6.42, closuresavings : 2, displaySystemSavings : 8.42 } } } } } } }, NOT_HOT_FILL : { bottleSize : { options : ["600", "601_1", "11_15", "16_3"], ANY : { currentDisplay : { options : ["NF10", "NF12", "NF04", "NF05"], NF10 : { futureDisplay : { options : ["NF12", "NF21", "NF15", "NF16", "NF17"], NF12: { neckSavings : 1.25, closuresavings : 0.5, displaySystemSavings : 1.75 }, NF21 : { neckSavings : 1.65, closuresavings : 0.6, displaySystemSavings : 2.25 }, NF15 : { neckSavings : 2.63, closuresavings : 1.05, displaySystemSavings : 3.68 }, NF16 : { neckSavings : 2.36, closuresavings : 1, displaySystemSavings : 3.36 }, NF17 : { neckSavings : 2.56, closuresavings : 1, displaySystemSavings : 3.56 } } }, NF12 : { futureDisplay : { options : ["NF21", "NF15", "NF16", "NF17"], NF21 : { neckSavings : 0.4, closuresavings : 0.1, displaySystemSavings : 0.5 }, NF15 : { neckSavings : 1.38, closuresavings : 0.55, displaySystemSavings : 1.93 }, NF16 : { neckSavings : 1.11, closuresavings : 0.5, displaySystemSavings : 1.61 }, NF17 : { neckSavings : 1.31, closuresavings : 0.5, displaySystemSavings : 1.81 } } }, NF04 : { futureDisplay : { options : ["NF19"], NF19 : { neckSavings : 1.19, closuresavings : 0.9, displaySystemSavings : 2.09 } } }, NF05 : { futureDisplay : { options : ["NF19"], NF19 : { neckSavings : 1.65, closuresavings : 1.1, displaySystemSavings : 2.75 } } } } }, 16_3 : { currentDisplay : { options : ["NF04", "NF05"], NF04 : { futureDisplay : { options : ["NF19"], NF19 : { neckSavings : 1.19, closuresavings : 0.9, displaySystemSavings : 2.09 } } }, NF05 : { futureDisplay : { options : ["NF19"], NF19 : { neckSavings : 1.65, closuresavings : 1.1, displaySystemSavings : 2.75 } } } } } } } } } } // New calculations function calculateResinSavings() { const result = numberProducedBottles * (getPerPreformWeightSavings("tons") + getPerClosureWeightSavings("tons")); console.log("Calculations => Yearly Resin Savings calculation results : " + result); calcResults2.calculations.resinSavingsTons = result; return result; } function calculateCO2Savings() { const result = numberProducedBottles * ((getPerPreformWeightSavings("tons") * getPercentageVirginResin() * CO2SavedPerTonVirginResin_Preform/1000) + (getPerPreformWeightSavings("tons") * selectedPET/100 * CO2SavedPerTonPCR_Preform/1000) + (getPerClosureWeightSavings("tons") * CO2SavedPerTonResin_Closure/1000)); setEloquaFieldValue("cALC2622OUT1881LWCO21", result.toFixed(1)); calcResults2.calculations.co2Savings = result; console.log("Calculations => Yearly CO2 calculation results : " + result); return result; } function calculateResinCost() { let result = numberProducedBottles * ((getPerPreformWeightSavings("tons") * getPercentageVirginResin() * CostPerTonVirginResin_Preform) + (getPerPreformWeightSavings("tons") * selectedPET/100 * CostPerTonPCR_Preform) + (getPerClosureWeightSavings("tons") * CostPerTonResin_Closure)); console.log("Calculations - Yearly Resin Cost calculation results : " + result); setEloquaFieldValue("cALC2622OUT1881LWResin1", result.toFixed(1)); setEloquaFieldValue("cALC2622OUT1881LWUSD1", formatter().format(result)); setEloquaFieldValue("cALC2622OUT1881LWEURO1", formatterEUR().format(calculateCostEURSavings(result))); calcResults2.calculations.resinCostSavings = result; calcResults2.calculations.resinCostSavingUSD = result; calcResults2.calculations.resinCostSavingEUR = calculateCostEURSavings(result); return result; } function getPerPreformWeightSavings(unit) { const _neckSavings = lookUp.application[selectedBeverageType].bottleSize[mapBottleSize(selectedBottleSize)].currentDisplay[selectedBottleSystem].futureDisplay[selectedNewBottleSystem].neckSavings; if (unit === 'grams') { console.log("Calculations in Grams => Neck Savings : " + _neckSavings ); return _neckSavings; } else { console.log("Calculations in Tons => Neck Savings : " + _neckSavings ); return _neckSavings/1000000; } } function getPerClosureWeightSavings(unit) { const _closureSavings = lookUp.application[selectedBeverageType].bottleSize[mapBottleSize(selectedBottleSize)].currentDisplay[selectedBottleSystem].futureDisplay[selectedNewBottleSystem].closuresavings; if (unit === "grams") { console.log("Calculations in Grams => Closure Savings : " + _closureSavings); return _closureSavings; } else { console.log("Calculations in Tons => Closure Savings : " + _closureSavings); return (_closureSavings/1000000); } } function getPercentageVirginResin() { return 1 - (selectedPET/100); }